package com.smart.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.pojo.SalesOrder;
import com.smart.mapper.SalesOrderMapper;
import com.smart.req.SalesReq;
import com.smart.resp.EchartsData;
import com.smart.resp.PopularProduct;
import com.smart.resp.SalesOrderResp;
import com.smart.service.ISalesOrderService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author lyj
 * @since 2023-05-15
 */
@Service
public class SalesOrderServiceImpl extends ServiceImpl<SalesOrderMapper, SalesOrder> implements ISalesOrderService {

    @Override
    public void queryByCondition(SalesReq salesReq, Page<SalesOrderResp> page) {
        QueryWrapper<SalesOrderResp> wrapper = new QueryWrapper<>();
        wrapper.apply(" so.del_flag=0 ")
                .eq(!ObjectUtils.isEmpty(salesReq.getUserId()), "so.user_id", salesReq.getUserId())
                .eq(!ObjectUtils.isEmpty(salesReq.getProductId()), "so.product_id", salesReq.getProductId())
                .like(!ObjectUtils.isEmpty(salesReq.getTitle()), "so.title", salesReq.getTitle());
        baseMapper.queryByCondition(wrapper, page);
    }

    @Override
    public int getCurrentOrders() {

        return baseMapper.getCurrentOrders();
    }

    @Override
    public BigDecimal getCurrentTurnover() {
        return baseMapper.getCurrentTurnover();
    }

    @Override
    public BigDecimal getTotalTurnover() {
        return baseMapper.getTotalTurnover();
    }

    @Override
    public PopularProduct getWeekPopularProduct() {
        return baseMapper.getWeekPopularProduct();
    }

    @Override
    public PopularProduct getYearPopularProduct() {
        return baseMapper.getYearPopularProduct();
    }

    @Override
    public List<EchartsData> getTurnoverData() {
        return baseMapper.getTurnoverData();
    }

    @Override
    public List<EchartsData> getSalesData() {
        return baseMapper.getSalesData();
    }

    @Override
    public List<EchartsData> getProfitData() {
        return baseMapper.getProfitData();
    }
}
